home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / -archivi / -recent2 / ged_scripts.lha / GED_Scripts / NewStruct.c < prev    next >
C/C++ Source or Header  |  1998-11-17  |  2KB  |  95 lines

  1. /* -----------------------------------------------------------------------------
  2.  
  3.   Scan handler looking for C structures.
  4.   
  5.   Scan handlers are plain functions (loadSeg()'ed): no standard C startup
  6.   code and no library calls permitted. We have to put string constants into
  7.   the code segment (DICE compiler: option -ms1).
  8.  
  9.   DICE:
  10.   
  11.   dcc struct.c -// -l0 -md -mRR -o golded:etc/scanner/struct
  12.  
  13.   ------------------------------------------------------------------------------
  14. */
  15.  
  16. #include <exec/types.h>
  17.  
  18. #define UPPER(a) ((a) & 95)
  19. #define REG(x) register __##x
  20.  
  21. ULONG
  22. ScanHandlerStruct(REG(d0) ULONG len, REG(a0) char **text, REG(a1) ULONG *line)
  23. {
  24.     const char *version = "$VER: Struct 1.3 (17.11.98)";
  25.  
  26.     UBYTE *from = *text;
  27.  
  28.     if (len > 8) {
  29.  
  30.         if ((from[0] == 't') && (from[1] == 'y') && (from[2] == 'p') && (from[3] == 'e') && (from[4] == 'd') && (from[5] == 'e') && (from[6] == 'f') && ((from[7] == ' ') || (from[7] == 9))) {
  31.  
  32.             // ignore typedef keyword
  33.  
  34.             len  -= 8;
  35.             from += 8;
  36.         }
  37.     }
  38.  
  39.     if (len > 7) {
  40.  
  41.         if ((from[0] == 's') && (from[1] == 't') && (from[2] == 'r') && (from[3] == 'u') && (from[4] == 'c') && (from[5] == 't') && ((from[6] == ' ') || (from[6] == 9))) {
  42.  
  43.             // found struct keyword
  44.  
  45.             UBYTE *last;
  46.  
  47.             for (last = from + len - 1; len && ((*last == 32) || (*last == 9)); --len)
  48.                --last;
  49.  
  50.             from += 7;
  51.             len  -= 7;
  52.  
  53.             // skip spaces between keyword and name
  54.             while((*from == ' ' || *from == 9) && len)
  55.                {
  56.                   ++from;
  57.                   --len;
  58.                }
  59.  
  60.             if ((*last != ',') && (*last != '*')) {
  61.  
  62.                 UWORD pos = len;
  63.  
  64.                 // check if there is a ';' in this line
  65.  
  66.                 while (pos--)
  67.                   {
  68.                      if (from[pos] == ';')
  69.                         {
  70.                            if (from[pos - 1] == '}')
  71.                               break;
  72.                            else
  73.                               return(FALSE);
  74.                         }
  75.                   }
  76.  
  77.                 if (*from != '{') {
  78.  
  79.                     *text = from;
  80.  
  81.                     for (len = 0; (from <= last) && (*from >= 48); ++len)
  82.  
  83.                         ++from;
  84.  
  85.                     return(len);
  86.                 }
  87.             }
  88.         }
  89.     }
  90.  
  91.     return(FALSE);
  92. }
  93.  
  94.  
  95.